package cn.lzd.mr.pvdemo;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

/**
 * Created by lzd on 2018/5/9.
 *
 * window启动注意点：
 *
 *  在https://github.com/SweetInk/hadoop-common-2.7.1-bin中下载winutils.exe,libwinutils.lib 拷贝到%HADOOP_HOME%\bin目录 。
 *  在https://github.com/SweetInk/hadoop-common-2.7.1-bin中下载hadoop.dll，并拷贝到c:\windows\system32目录中。
 *
 *  配置环境变量 hadoop_home 和 path=hadoop_home\bin;hadoop_home\sbin
 *
 *  window下读取路径必须指到具体某个文件；如果多个文件可以 F:\\input\\*.txt
 *
 */
public class PvMasterLocal {

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf);

        job.setJarByClass(PvMasterLocal.class);

        job.setMapperClass(PvMapper.class);
        job.setReducerClass(PvReduce.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        job.setInputFormatClass(TextInputFormat.class);
        FileInputFormat.setInputPaths(job, new Path("F:\\tmp\\input\\info1.log"));

        job.setOutputFormatClass(TextOutputFormat.class);
        FileOutputFormat.setOutputPath(job, new Path("F:\\tmp\\output"));

        //job.setNumReduceTasks(1);

        boolean res = job.waitForCompletion(true);
        System.exit(res ? 0 : 1);

    }
}
